<template>
  <div class="bgc">
    <div class="container">
      <div style="color: #0094ff">
        欢迎来到<span style="color: #fc5531" class="named">南风未起</span>的博客
      </div>
      <van-form @submit="onSubmit">
        <van-cell-group inset>
          <van-field
            v-model="username"
            name="username"
            label="用户名"
            placeholder="用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
          <van-field
            v-model="password"
            type="password"
            name="password"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
        </van-cell-group>
        <div style="margin: 16px">
          <van-button round block type="primary" native-type="submit">
            登录
          </van-button>
          <br />
          <van-button round block @click="register"> 注册 </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>


<script setup>
import { onMounted, ref } from "vue";
import { getlogin } from "../api/getlogin";
import { showSuccessToast, showFailToast } from "vant";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { setstorage } from "../utils/local";
const username = ref("");
const password = ref("");
const router = useRouter();
const store = useStore();
const onSubmit = (values) => {
  getlogin(values).then((res) => {
    if (res.data.status == 200) {
      showSuccessToast("欢迎进入我的博客！");
      setstorage("userinfo", res.data.username);
      store.commit("setuser", res.data.time);
      router.push({
        path: "/details",
      });
    }
    if (res.data.status == 404) {
      showFailToast("账号或密码错误！");
    }
  });
};
const register = () => {
  router.push({
    path: "/register",
  });
};
onMounted(async () => {
  // const { data: res } = await getlogin();
  // console.log(res);
});
</script>
 


<style scoped>
.bgc {
  width: 100%;
  height: 100vh;
  background: url(../assets/background.jpg) 0 0n0o0-0r0e0p0e0a0t0 0c0e0n0t0e0r0
    0center;
  background-size: cover;
  /* 让背景图基于容器大小伸缩 */
  background-attachment: fixed;
  /* 当内容高度大于图片高度时，背景图像的位置相对于viewport固定 */
  background-color: #cccccc;
  /* 设置背景颜色，背景图加载过程中会显示背景色 */
}

.container {
  position: relative;
  top: 30%;
}

.named {
  color: hsla(0, 0%, 0%, 0.9);
  font: normal 34px Varela Round, sans-serif;
  height: 140px;
  left: 0;
  letter-spacing: 5px;
  /* margin: -80px 0 0 0; */
  /* position: absolute; */
  text-align: center;
  text-transform: uppercase;
  /* top: 50%; */
  width: 100%;
  animation: move linear 2000ms infinite;
}

@keyframes move {
  0% {
    text-shadow: 4px -4px 0 hsla(0, 100%, 50%, 1),
      3px -3px 0 hsla(0, 100%, 50%, 1), 2px -2px 0 hsla(0, 100%, 50%, 1),
      1px -1px 0 hsla(0, 100%, 50%, 1), -4px 4px 0 hsla(180, 100%, 50%, 1),
      -3px 3px 0 hsla(180, 100%, 50%, 1), -2px 2px 0 hsla(180, 100%, 50%, 1),
      -1px 1px 0 hsla(180, 100%, 50%, 1);
  }

  25% {
    text-shadow: -4px -4px 0 hsla(180, 100%, 50%, 1),
      -3px -3px 0 hsla(180, 100%, 50%, 1), -2px -2px 0 hsla(180, 100%, 50%, 1),
      -1px -1px 0 hsla(180, 100%, 50%, 1), 4px 4px 0 hsla(0, 100%, 50%, 1),
      3px 3px 0 hsla(0, 100%, 50%, 1), 2px 2px 0 hsla(0, 100%, 50%, 1),
      1px 1px 0 hsla(0, 100%, 50%, 1);
  }

  50% {
    text-shadow: -4px 4px 0 hsla(0, 100%, 50%, 1),
      -3px 3px 0 hsla(0, 100%, 50%, 1), -2px 2px 0 hsla(0, 100%, 50%, 1),
      -1px 1px 0 hsla(0, 100%, 50%, 1), 4px -4px 0 hsla(180, 100%, 50%, 1),
      3px -3px 0 hsla(180, 100%, 50%, 1), 2px -2px 0 hsla(180, 100%, 50%, 1),
      1px -1px 0 hsla(180, 100%, 50%, 1);
  }

  75% {
    text-shadow: 4px 4px 0 hsla(180, 100%, 50%, 1),
      3px 3px 0 hsla(180, 100%, 50%, 1), 2px 2px 0 hsla(180, 100%, 50%, 1),
      1px 1px 0 hsla(180, 100%, 50%, 1), -4px -4px 0 hsla(0, 100%, 50%, 1),
      -3px -3px 0 hsla(0, 100%, 50%, 1), -2px -2px 0 hsla(0, 100%, 50%, 1),
      -1px -1px 0 hsla(0, 100%, 50%, 1);
  }

  100% {
    text-shadow: 4px -4px 0 hsla(0, 100%, 50%, 1),
      3px -3px 0 hsla(0, 100%, 50%, 1), 2px -2px 0 hsla(0, 100%, 50%, 1),
      1px -1px 0 hsla(0, 100%, 50%, 1), -4px 4px 0 hsla(180, 100%, 50%, 1),
      -3px 3px 0 hsla(180, 100%, 50%, 1), -2px 2px 0 hsla(180, 100%, 50%, 1),
      -1px 1px 0 hsla(180, 100%, 50%, 1);
  }
}
</style>